﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Hkwl.WorldExpo.Merchant.Common;
using Hkwl.WorldExpo.Merchant.Model;
using Hkwl.WorldExpo.Merchant.Service;

namespace Hkwl.WorldExpo.Merchant.Web
{
    public partial class GroupList : BaseCheckPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataBind_Group(0);
            }
        }

        protected void DataBind_Group(int recordcount)
        {
            int merchantId = 1;
            if (Session["MerchantId"] != null)
            {
                merchantId = int.Parse(Session["MerchantId"].ToString());
            }
            this.rpGroupList.DataSource = ServiceLocator.IClientService.GetNxGroupCollection(merchantId);
            this.rpGroupList.DataBind();
         }

        protected void rpGroupList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                NxGroup group = (NxGroup)e.Item.DataItem;
                Label lbNum = (Label)e.Item.FindControl("lbNum");
                lbNum.Text = (e.Item.ItemIndex + 1).ToString();
                Label lbGroupName = (Label)e.Item.FindControl("lbGroupName");
                lbGroupName.Text = group.GroupName;
                HyperLink hlClientList = (HyperLink)e.Item.FindControl("hlClientList");
                hlClientList.NavigateUrl = string.Format("GroupClientList.aspx?GroupId={0}", group.GroupId.ToString());
                HyperLink hlModifyGroupClient = (HyperLink)e.Item.FindControl("hlModifyGroupClient");
                hlModifyGroupClient.NavigateUrl = string.Format("AddClientToGroup.aspx?GroupId={0}", group.GroupId.ToString());
                HyperLink hlModifyGroupName = (HyperLink)e.Item.FindControl("hlModifyGroupName");
                hlModifyGroupName.NavigateUrl = string.Format("GroupModify.aspx?GroupId={0}", group.GroupId.ToString());
                HyperLink hlDelGroup = (HyperLink)e.Item.FindControl("hlDelGroup");
                hlDelGroup.NavigateUrl = string.Format("Operate.aspx?GroupId={0}&OpType=GroupDel", group.GroupId.ToString());
            }
        }

    }
}
